home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_12_06
/
gotwals
/
fact1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-01
|
705b
|
29 lines
====================== Listing 1 ======================
/* fact1.cpp
demo factorial program
---------------------- */
#include <stdio.h>
#include <string.h>
#include "largeint.h"
#include "misc.h"
int main() {
const int bufSize = 50000; // max decimal digits
char buf[bufSize];
int choice;
LargeInt result = 1;
printf("Calculate factorial of: ");
scanf("%d", &choice);
for (int i = 2; i <= choice; i++)
result *= i;
if (result.binToDec(buf, bufSize) != NULL) {
printf("\n%d! = \n%s\n", choice, buf);
printf("\nwhich has %d digits\n", strlen(buf));
}
else
printf("Output string buffer too small\n");
return 0;
}